import Vue from 'vue'

import VueRouter from 'vue-router'
Vue.use(VueRouter)

//1. 创建组件
import Home from '../components/Home.vue';
import News from '../components/News.vue';
import User from '../components/User.vue';
  import UserAdd from '../components/User/UserAdd.vue';
  import UserList from '../components/User/UserList.vue';
import NewsDetail from '../components/NewsDetail.vue';
import ProductDetail from '../components/ProductDetail.vue';
//2. 配置路由
const routes = [
  { path: '/home', component: Home },
  { path: '/news', component: News, name:'newsName' },/*命名路由*/
  { 
    path: '/user', 
    component: User, 
    // 配置嵌套路由
    children:[
      {path:'userAdd', component:UserAdd},
      {path:'userList', component:UserList}
    ]
  },
  { path: '/newsDetail/:aid', component: NewsDetail }, /*配置动态路由*/
  { path: '/productDetail', component: ProductDetail },
  { path: '*', redirect: '/home'}  /*默认跳转路由 */
]
//3. 实例化VueRouter
const router = new VueRouter({
  mode:'history',  /*编程式路由默认的hash模式改为history模式. hash模式在路径中带#号,history模式不带#,但是需在web服务器里配置*/
  routes // (缩写) 相当于 routes: routes
})

// 路由分离需暴露路由
export default router;